<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue选项卡</title>
    <script src="lib/vue.js"></script>
    <style>
        ul {
            height: 40px;
            padding-left: 0;
            margin: 0;
        }

        ul>li {
            display: block;
            float: left;
            list-style: none;
            height: 40px;
            line-height: 40px;
            background-color: antiquewhite;
            text-align: center;
            padding: 0 20px;
            border: 1px solid black;
        }

        li:nth-child(2) {
            border-left: none;
            border-right: none;
        }

        .tab>div {
            clear: both;
            border: 1px solid red;
            height: 200px;
            width: 300px;
            display: none;
        }

        .tab>div img {
            width: 100%;
            height: 100%;
        }

        .active {
            background-color: orange;
        }

        .tab>.current {
            display: block;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="tab">
            <ul>
                <li @click='change(index)' :class="currentIndex == index?'active':''" v-for='(item,index) in list'
                    :key="item.id">
                    {{item.title}}</li>
            </ul>
            <div :class="currentIndex == index?'current':''" v-for='(item,index) in list' :key='item.id'>
                <img :src="item.path">
            </div>
        </div>
    </div>

    <script>
        new Vue({
            el: '#app',
            data: {
                currentIndex: 0,
                list: [{
                        id: 1,
                        title: 'apple',
                        path: '../mobile/images/banner_1.jpg'
                    },
                    {
                        id: 2,
                        title: 'orange',
                        path: '../mobile/images/banner_1.png'
                    },
                    {
                        id: 3,
                        title: 'banana',
                        path: '../mobile/images/banner_1.jpg'
                    },
                ]
            },
            methods: {
                change(index) {
                    this.currentIndex = index;
                    console.log(index);
                }
            }
        })
    </script>
</body>

</html>